package com.mcgrady.start;

import org.junit.Test;

import java.util.Random;

/**
 * @author McGrady
 */
public class BaseOperatorsTest {
    @Test
    public void baseOperator() {
        System.out.println(10 / 4);
        System.out.println(10.0 / 4);
        System.out.println(0 % 3);
        System.out.println(5 % -3);
        System.out.println(-5 % 3);
    }

    @Test
    public void selfOperator() {
        int a = 1;
        System.out.println(a++);
        System.out.println(++a);

        short sh = 100;
        sh = sh++;
        System.out.println(sh);
        sh = ++sh;
        System.out.println(sh);
    }

    @Test
    public void assignOperator() {
        int a = 1;
        System.out.println(a += 5);
        System.out.println(a -= 4);
        System.out.println(a *= 3);
        System.out.println(a /= 5);
        System.out.println(a %= 7);
        System.out.println(a);
    }

    @Test
    public void relationOperator() {
        int a = 9;
        System.out.println(a >= 11);
        System.out.println(a <= 11);
        System.out.println(a == 11);
        System.out.println(a > 11);
        System.out.println(a < 11);
        System.out.println(a != 11);
    }
    @Test
    public void logic() {
        int a = 7;
        System.out.println(a <= 9 && a == 7);
        System.out.println(a == 9 || a != 7);
        System.out.println(!(a == 9));
        System.out.println(a == 9 || a == 1 && a == 7);
    }

    @Test
    public void bit() {
        int a = 10;
        System.out.println(a != 10 & a++ == 10);
        System.out.println(a);
    }
    @Test
    public void ternary(){
        double score = 75;
        String result = (score >100 || score < 0) ? "分数有问题" :( score >= 80 ? "优秀" :(score >= 60? "及格" : "不及格"));
        System.out.println(result);
    }
    @Test
    public void mathApi(){
        System.out.println(Math.max(1, 2));
        System.out.println(Math.min(1, 2));
        System.out.println(Math.ceil(1.3));
        System.out.println(Math.floor(2.8));
        System.out.println(Math.abs(-4.7));
        System.out.println(Math.round(-12.6));
        System.out.println(Math.pow(2, 4));
    }
    @Test
    public void randomApi(){
        Random random = new Random();
        System.out.println(random.nextDouble()+2);
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
        System.out.println(random.nextInt(10));
    }
}
